package cn.zlj.pethome.org.controller;

import cn.zlj.pethome.basic.QueryResult;
import cn.zlj.pethome.basic.annotation.LogAnno;
import cn.zlj.pethome.basic.query.BaseQuery;
import cn.zlj.pethome.basic.util.AjaxResult;
import cn.zlj.pethome.org.domain.TSystemdictionarydetail;
import cn.zlj.pethome.org.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dy")
@LogAnno
public class DictionaryController {
    @Autowired
    DictionaryService dictionaryService;

    @PostMapping
    @LogAnno(method = "查询所有字典分页列表")
    public QueryResult<TSystemdictionarydetail> queryPage(@RequestBody BaseQuery query) {
        QueryResult<TSystemdictionarydetail> result = dictionaryService.queryByPage(query);
        return result;
    }

    @PutMapping
    @LogAnno(method = "修改或者增加字典")
    public AjaxResult saveAndUpdate(@RequestBody TSystemdictionarydetail t){
        if(t.getId()==null){
            dictionaryService.add(t);
        }else {
            dictionaryService.update(t);
        }
        return  AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    @LogAnno(method = "根据id删除字典")
    public AjaxResult del(@PathVariable("id") Long id){
        dictionaryService.delete(id);
        return  AjaxResult.me().success();
    }
    @PatchMapping
   @LogAnno(method = "根据id批量删除字典")
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        dictionaryService.batchDel(ids);
        return AjaxResult.me().success();
    }
}
